package com.ccit.user.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ccit.common.exception.GymException;
import com.ccit.model.User;
import com.ccit.user.service.UserService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/api/area")
public class UserApiController {
    @Autowired
    private UserService userService;

    //根据id查询场地信息
    @ApiOperation("根据Id查询会员")
    @GetMapping("/getById/{userId}")
    public User getById(
            @ApiParam(value = "会员id",required = true)
            @PathVariable Long memberId){
        User user = userService.getById(memberId);
        return user;
    }

    @ApiOperation("根据手机号查询会员")
    @GetMapping("/getById/{phone}")
    public User getByPhone(
            @ApiParam(value = "会员手机号",required = true)
            @PathVariable String  phone){
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone", phone);
        queryWrapper.orderByDesc("create_time");

        User one = userService.getOne(queryWrapper);
        if (one!=null){
            return one;
        }else {
            throw new GymException(202,"查无此会员");
        }

    }

}
